﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Pongster
{
    public class PopUpScreen : BaseGameState
    {
        PictureBox backgroundImage;
        Label message;


        public PopUpScreen(Game game, GameStateManager manager)
            : base(game, manager)
        {
            IsPopup = true;
        }

        public override void Initialize()
        {
            base.Initialize();

            transColor.A = 150;

        }

        protected override void LoadContent()
        {
            base.LoadContent();

            ContentManager Content = GameRef.Content;

            menuFont = Content.Load<SpriteFont>(@"Fonts\MenuFont");
            ControlManager = new ControlManager(menuFont, GameRef);

            Rectangle rect = new Rectangle(Settings.basescreenWidth / 2 - 470 / 2, Settings.basescreenHeight / 2 - 241 / 2, 470, 242);

            backgroundImage = new PictureBox(Content.Load<Texture2D>(@"Backgrounds\popupbg"), rect);
            ControlManager.Add(backgroundImage);
            
            message = new Label();
            message.Text = "   Escape = Exit \n \n Enter = Resume";
            message.Size = message.SpriteFont.MeasureString(message.Text);
            message.Position = new Vector2(Settings.basescreenWidth / 2 - message.Size.X /2 - 12, Settings.basescreenHeight / 2 - 120 / 2);
            message.Color = Color.Ivory;

            transColor.A = 150;
            
            ControlManager.Add(message);
        }

        

        public override void Update(GameTime gameTime)
        {
            
            if (InputHandler.KeyReleased(Keys.Escape))
            {
                Settings.mediaPlayerFree = true; 
                GameRef.SoundManager.StopAll();
                //StateManager.ChangeState(GameRef.TitleScreen);
                Transition(ChangeType.Change, GameRef.TitleScreen);                
            }

            if (InputHandler.KeyReleased(Keys.Enter) || InputHandler.KeyReleased(Keys.Space))
            {
                Settings.mediaPlayerFree = true;
                //StateManager.PopState();
                Transition(ChangeType.Pop, null);
            }

            ControlManager.Update(gameTime);

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            GameRef.SpriteBatch.Begin();
           
            base.Draw(gameTime);

            ControlManager.Draw(GameRef.SpriteBatch);

            GameRef.SpriteBatch.End();
        }


    }
}
